<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false"
    :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="rules" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()"
      label-width="120px">

      <el-tabs type="border-card">
        <el-tab-pane label="实名信息">
          <el-form-item label="姓名">
            <el-input v-model="dataForm.realName" placeholder="姓名"></el-input>
          </el-form-item>
          <el-form-item label="身份证">
            <el-input v-model="dataForm.idCard" placeholder="身份证"></el-input>
          </el-form-item>
          <el-form-item label="手机号">
            <el-input v-model="dataForm.mobile" placeholder="手机号"></el-input>
          </el-form-item>


        </el-tab-pane>

        <el-tab-pane label="发薪卡">
          <el-form-item label="发薪卡名  ">
            <el-input v-model="dataForm.payCardName" placeholder="发薪卡名  "></el-input>
          </el-form-item>
          <el-form-item label="所属支行 ">
            <el-input v-model="dataForm.payCardBranch" placeholder="发薪卡名  "></el-input>
          </el-form-item>
          <el-form-item label="发薪卡号">
            <el-input v-model="dataForm.payCard" placeholder="发薪卡号"></el-input>
          </el-form-item>

        </el-tab-pane>
        <el-tab-pane label="其他">
          <el-form-item label="微信号">
            <el-input v-model="dataForm.username" placeholder="微信号"></el-input>
          </el-form-item>
          <el-form-item label="qq号">
            <el-input v-model="dataForm.qqNo" placeholder="qq号"></el-input>
          </el-form-item>

          <el-form-item label="紧急联系人">
            <el-input v-model="dataForm.urgencyName" placeholder="紧急联系人"></el-input>
          </el-form-item>

          <el-form-item label="紧急联系人电话">
            <el-input v-model="dataForm.urgencyPhone" placeholder="紧急联系人电话"></el-input>
          </el-form-item>
          <el-form-item label="与其关系">
            <el-radio-group v-model="dataForm.urgencyRelation">
              <el-radio :label="sd.id" :value="sd.id" v-for="sd in kjjxzcd">
                {{sd.dictLabel }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="入职照片">
            <div class="xzcsretrt" v-if="visible">
              <dimg :dximg="dataForm.jobImg" @getimg="xzczxtrt"></dimg>
            </div>
          </el-form-item>
        </el-tab-pane>
      </el-tabs>



      <!-- <el-form-item label="余额" prop="balance">
        <el-input v-model="dataForm.balance" placeholder="余额"></el-input>
      </el-form-item>
      <el-form-item label="入职企业" prop="companyId">
        <el-input v-model="dataForm.companyId" placeholder="入职企业"></el-input>
      </el-form-item>
      <el-form-item label="员工工号" prop="companyNo">
        <el-input v-model="dataForm.companyNo" placeholder="员工工号"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="用户名 微信号" prop="username">
        <el-input v-model="dataForm.username" placeholder="用户名 微信号"></el-input>
      </el-form-item> -->

      <!-- <el-form-item label="密码" prop="password">
        <el-input v-model="dataForm.password" placeholder="密码"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="昵称" prop="name">
        <el-input v-model="dataForm.name" placeholder="昵称"></el-input>
      </el-form-item> -->

      <!-- <el-form-item label="头像" prop="headUrl">
        <el-input v-model="dataForm.headUrl" placeholder="头像"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="性别   0：男   1：女    2：保密" prop="gender">
        <el-input v-model="dataForm.gender" placeholder="性别   0：男   1：女    2：保密"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="邮箱" prop="email">
        <el-input v-model="dataForm.email" placeholder="邮箱"></el-input>
      </el-form-item> -->

      <!-- <el-form-item label="籍贯地址" prop="idAddress">
        <el-input v-model="dataForm.idAddress" placeholder="籍贯地址"></el-input>
      </el-form-item>
      <el-form-item label="是否实名" prop="isAuthentication">
        <el-input v-model="dataForm.isAuthentication" placeholder="是否实名"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="是否住宿" prop="isReside">
        <el-input v-model="dataForm.isReside" placeholder="是否住宿"></el-input>
      </el-form-item> -->
      <!-- 
      <el-form-item label="户名 持卡人" prop="payName">
        <el-input v-model="dataForm.payName" placeholder="户名 持卡人"></el-input>
      </el-form-item> -->

      <!-- <el-form-item label="创建时间" prop="createTime">
        <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime">
        <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
      </el-form-item> -->
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">确定</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import baseService from "@/service/baseService";
import { ElMessage } from "element-plus";
const emit = defineEmits(["refreshDataList"]);
import { dxget, zkjsd, transferTimeYMD } from "@/utils/utils"
import dimg from "@/components/dimg.vue";
const visible = ref(false);
const dataFormRef = ref();
const kjjxzcd  = ref([])
const dataForm = reactive({
  id: '', balance: '', companyId: '', companyNo: '', username: '', mobile: '', password: '', createDate: '', name: '', realName: '', headUrl: '', gender: '', email: '', idCard: '', idAddress: '', isAuthentication: '', isReside: '', payCard: '', payCardName: '', payName: '', qqNo: '', urgencyName: '', urgencyRelation: '', urgencyPhone: '', createTime: '', updateTime: ''
});

const rules = ref({
  balance: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  companyId: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  companyNo: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  username: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  mobile: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  password: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  name: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  realName: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  headUrl: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  gender: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  email: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  idCard: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  idAddress: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  isAuthentication: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  isReside: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  payCard: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  payCardName: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  payName: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  qqNo: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  urgencyName: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  urgencyRelation: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  urgencyPhone: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  createTime: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  updateTime: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ]
});

const init = (id?: number) => {
  visible.value = true;
  dataForm.id = "";

  // 重置表单数据
  if (dataFormRef.value) {
    dataFormRef.value.resetFields();
  }

  if (id) {
    getInfo(id);
  }
};
const xzczxtrt = (data) => {
  dataForm.jobImg = data
}
// 获取信息
const getInfo = (id: number) => {
  baseService.get("/api/user/" + id).then((res) => {
    Object.assign(dataForm, res.data);
  });
};

// 表单提交
const dataFormSubmitHandle = () => {
  dataFormRef.value.validate((valid: boolean) => {
    if (!valid) {
      return false;
    }
    (!dataForm.id ? baseService.post : baseService.put)("/api/user", dataForm).then((res) => {
      ElMessage.success({
        message: '成功',
        duration: 500,
        onClose: () => {
          visible.value = false;
          emit("refreshDataList");
        }
      });
    });
  });
};

defineExpose({
  init
});

const getsd = async () => {

  const { list } = await zkjsd("1766378831330951170")
  console.log(list);
  kjjxzcd.value = list
}
getsd()


</script>
